Skip to content

data/selinux, packaging: assign a default label for /tmp/snap-private-tmp, set it during installation - #17403

Merged
sergiocazzolato merged 3 commits into
canonical:masterfrom
bboozzoo:bboozzoo/selinux-clean-snap-private-tmp
Jul 23, 2026
Merged

data/selinux, packaging: assign a default label for /tmp/snap-private-tmp, set it during installation#17403
sergiocazzolato merged 3 commits into
canonical:masterfrom
bboozzoo:bboozzoo/selinux-clean-snap-private-tmp

Conversation

@bboozzoo

Copy link
Copy Markdown
Contributor

The recently merged changes from 2.76.3 added a line creating /tmp/snap-private-tmp in %post. However, since we have no default label assigned for that path and the %post script is executed by rpm, the path got incorrect label:

garden:fedora-44-64 .../tests/main/selinux-clean# ls -lZ /tmp/
total 1728
drwxr-xr-x. 2 root root unconfined_u:object_r:user_tmp_t:s0           120 Jul 23 16:23 fs-initial
-rw-------. 1 root root unconfined_u:object_r:user_tmp_t:s0       1759910 Jul 23 16:19 gojq.tar.gz
drwx------. 4 root root unconfined_u:object_r:rpm_script_tmp_t:s0      80 Jul 23 16:23 snap-private-tmp

The branch updates the default file labels so that we get snappy_tmp_t, ensures we get the right label during installation and allows the snap command to probe for the directory.

@zyga zyga left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!!!

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes SELinux labeling for /tmp/snap-private-tmp on RPM-based systems by adding a default file context for the directory and ensuring it is relabeled after the snappy SELinux policy module is installed, so snap-confine and the snap CLI behave correctly under SELinux enforcement.

Changes:

  • Add an SELinux file-context entry to label /tmp/snap-private-tmp as snappy_tmp_t.
  • Update Fedora and openSUSE RPM %post selinux scriptlets to create the directory (if needed) and restorecon it after installing the SELinux module.
  • Allow snappy_cli_t to getattr the snappy_tmp_t directory so the snap command can probe for its presence.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
packaging/opensuse/snapd.spec Create and relabel /tmp/snap-private-tmp after loading the SELinux module on openSUSE.
packaging/fedora/snapd.spec Create and relabel /tmp/snap-private-tmp after loading the SELinux module on Fedora.
data/selinux/snappy.te Permit snap CLI domain to getattr the labeled directory for existence probing.
data/selinux/snappy.fc Define the default SELinux label for /tmp/snap-private-tmp as snappy_tmp_t.

@codecov

codecov Bot commented Jul 23, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 78.93%. Comparing base (ff400ce) to head (299a253).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #17403   +/-   ##
=======================================
  Coverage   78.93%   78.93%           
=======================================
  Files        1391     1390    -1     
  Lines      196009   195981   -28     
  Branches     2462     2462           
=======================================
- Hits       154727   154707   -20     
+ Misses      32013    31993   -20     
- Partials     9269     9281   +12     
Flag Coverage Δ
unittests 78.93% <ø> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@olivercalder olivercalder left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@github-actions github-actions Bot added the Auto rerun spread Auto reruns spread up to 4 times in non-draft PRs w/ >=1 approval and <20 fails in any fund. system label Jul 23, 2026
@github-actions

github-actions Bot commented Jul 23, 2026

Copy link
Copy Markdown

Thu Jul 23 22:57:37 UTC 2026
The following results are from: https://github.com/canonical/snapd/actions/runs/30033890670

Failures:

Preparing:

  • openstack-arm:ubuntu-24.04-arm-64:tests/main/snap-seccomp-blocks-certain-creat
  • openstack-arm:ubuntu-24.04-arm-64:tests/main/snap-seccomp-blocks-certain-mknod

Executing:

  • openstack:opensuse-tumbleweed-64:tests/main/manpages
  • openstack:opensuse-tumbleweed-64:tests/main/services-watchdog
  • openstack:ubuntu-core-24-64:tests/main/snap-debug-raa
  • openstack:ubuntu-22.04-64:tests/main/lxd-mount-units

Restoring:

  • openstack:ubuntu-core-24-64:tests/main/snap-debug-raa

Skipped tests from snapd-testing-skip

If you wish to have any of the below tests run in your PR, in your PR description, add 'unskip:' followed by a copy-and-pasted list of the below tests you wish to run (unskip plus test list must be valid yaml)

  • garden:ubuntu-25.10-64:tests/main/apparmor-prompting-support
  • openstack-arm:ubuntu-24.04-arm-64:tests/main/i18n
  • openstack-arm:ubuntu-core-24-arm-64:tests/main/i18n
  • openstack:debian-sid-64:tests/main/interfaces-network-status-classic
  • openstack:debian-sid-64:tests/main/interfaces-xdg-portal-permission-store
  • openstack:ubuntu-24.04-64:tests/main/apparmor-prompting-flag-restart
  • openstack:ubuntu-24.04-64:tests/main/apparmor-prompting-integration-tests
  • openstack:ubuntu-24.04-64:tests/main/apparmor-prompting-prompt-restoration
  • openstack:ubuntu-24.04-64:tests/main/apparmor-prompting-smoke
  • openstack:ubuntu-24.04-64:tests/main/apparmor-prompting-snapd-startup
  • openstack:ubuntu-24.04-64:tests/main/apparmor-prompting-support
  • openstack:ubuntu-24.04-64:tests/main/i18n
  • openstack:ubuntu-24.04-64:tests/main/interfaces-requests-activates-handlers
  • openstack:ubuntu-25.10-64:tests/main/apparmor-prompting-flag-restart
  • openstack:ubuntu-25.10-64:tests/main/apparmor-prompting-integration-tests
  • openstack:ubuntu-25.10-64:tests/main/apparmor-prompting-prompt-restoration
  • openstack:ubuntu-25.10-64:tests/main/apparmor-prompting-smoke
  • openstack:ubuntu-25.10-64:tests/main/apparmor-prompting-snapd-startup
  • openstack:ubuntu-25.10-64:tests/main/apparmor-prompting-support
  • openstack:ubuntu-25.10-64:tests/main/interfaces-requests-activates-handlers
  • openstack:ubuntu-26.04-64:tests/main/apparmor-prompting-flag-restart
  • openstack:ubuntu-26.04-64:tests/main/apparmor-prompting-integration-tests
  • openstack:ubuntu-26.04-64:tests/main/apparmor-prompting-prompt-restoration
  • openstack:ubuntu-26.04-64:tests/main/apparmor-prompting-smoke
  • openstack:ubuntu-26.04-64:tests/main/apparmor-prompting-snapd-startup
  • openstack:ubuntu-26.04-64:tests/main/apparmor-prompting-support
  • openstack:ubuntu-26.04-64:tests/main/i18n
  • openstack:ubuntu-26.04-64:tests/main/interfaces-requests-activates-handlers

@bboozzoo bboozzoo added the cross-distro Runs all spread systems in parallel label Jul 23, 2026
bboozzoo added 3 commits July 23, 2026 15:28
Signed-off-by: Maciej Borzecki <maciej.borzecki@canonical.com>
…ling the selinux policy package

Signed-off-by: Maciej Borzecki <maciej.borzecki@canonical.com>
…mp presence

Signed-off-by: Maciej Borzecki <maciej.borzecki@canonical.com>
@sergiocazzolato
sergiocazzolato force-pushed the bboozzoo/selinux-clean-snap-private-tmp branch from 2991227 to 299a253 Compare July 23, 2026 18:28
@sergiocazzolato
sergiocazzolato merged commit ba46c97 into canonical:master Jul 23, 2026
202 of 219 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Auto rerun spread Auto reruns spread up to 4 times in non-draft PRs w/ >=1 approval and <20 fails in any fund. system cross-distro Runs all spread systems in parallel

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants